package com.treasure.web.command.response;

import com.treasure.common.utils.MD5Utils;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * @author sunhongmin
 * @date 2023/11/11 10:57
 * @description
 */
@Data
public class CorpAccountTokenResponse implements Serializable {

    private Long id;
    /**
     * 企业ID
     */
    private String corpId;
    /**
     * AppKey
     */
    private String appKey;
    /**
     * AccessToken
     */
    private String accessToken;
    /**
     * 授权状态 0:未授权 1:已授权
     */
    private Integer authorizationStatus;
    /**
     * 有效期
     */
    private LocalDateTime expireDate;
    /**
     * ip白名单
     */
    private String ipWhitelist;


    public boolean hasEffectiveCorp() {
        if (Objects.equals(authorizationStatus, 1)) {
            return expireDate.isAfter(LocalDateTime.now());
        }

        return false;
    }

    public String auth() {
        return MD5Utils.md5(appKey + "#" + accessToken);
    }

    public boolean checkAuth(String auth) {
        return Objects.equals(auth(), auth);
    }

}
